﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioManager : MonoBehaviour
{
    public GameManager gameManager;
    AudioSource audioSource;

    private void Awake()
    {
        audioSource = GetComponent<AudioSource>();
        gameManager = FindObjectOfType<GameManager>();
    }

    private void Start()
    {
        DontDestroyOnLoad(gameObject);
    }

    private void Update()
    {
        if (gameManager == null)
        {
            gameManager = FindObjectOfType<GameManager>();
        }
        if (gameManager.isLose)
        {
            if (audioSource.volume >= 0.1f)
            {
                audioSource.volume -= 0.01f;
            }
        }
        else
        {
            if (audioSource.volume <= 0.5f)
            {
                audioSource.volume += 0.01f;
            }
        }
    }
}
